package thread;

import java.util.concurrent.locks.ReentrantLock;

public class SynchronizeLock {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            lock.lock();
            try {
                System.out.println("thread 1 lock");
            } finally {
                lock.unlock();
                System.out.println("thread 1 unlock");
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("thread 2 lock");
                } finally {
                    System.out.println("thread 2 unlock");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
